package com.zw.access.controller;


import com.zw.access.service.AccessRegisterService;
import com.zw.commons.log.annotation.Log;
import com.zw.commons.log.enums.BusinessType;
import com.zw.commons.utlis.JwtHelper;
import com.zw.object.access.AccessRegister;
import com.zw.object.result.Result;
import com.zw.object.vo.AccessRegisterVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 出入登记表 前端控制器
 * </p>
 *
 * @author zw
 * @since 2023-03-12
 */
@RestController
@RequestMapping("/access/access-register")
@Api(tags = "出入登记")
public class AccessRegisterController {
    @Autowired
    private AccessRegisterService accessRegisterService;

    @ApiOperation("出入登记")
    @PostMapping("/register")
    @Log(title = "出入登记", businessType = BusinessType.INSERT)
    public Result register(@Validated @RequestBody AccessRegister accessRegister, HttpServletRequest request) {
        accessRegister.setCreateBy(JwtHelper.getUsername(request.getHeader("token")));
        return accessRegisterService.register(accessRegister);
    }

    @ApiOperation("出入登记列表")
    @PostMapping("/list")
    @Log(title = "出入登记列表", businessType = BusinessType.SELECT)
    public Result registerList(@Validated @RequestBody AccessRegisterVo vo) {
        return accessRegisterService.pageList(vo);
    }
}

